package com.ptswitch.material.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ptswitch.material.model.common.Uzer;

public interface UserMapper {
    @Select("select * from uzer where id = #{userId}")
    Uzer findById(@Param("userId") long userId);

    @Select("select * from uzer where username = #{username}")
    Uzer findByUsername(@Param("username") String username);

    @Select("select * from uzer where username = #{username} and password = #{password}")
    Uzer findByUsernameAndPassword(@Param("usernmae") String username,//
            @Param("password") String password);

    @Select("select * from uzer where department = #{department}")
    List<Uzer> findByDepartment(@Param("department") int department, long first, long size);

    @Select("select * from uzer order by username asc")
    List<Uzer> findAll(long first, long size);

    @Select("select count(*) from uzer")
    long countAll();

    @Select("select * from uzer where username like #{username}")
    List<Uzer> likeByUsername(@Param("username") String username, long first, long size);

    @Select("select count(*) from uzer where username like #{username}")
    long countLikeByUsername(@Param("username") String username);

    //
    @Insert("insert into uzer(username,realname)"//
            + " values(#{user.username},#{user.realname}) returning id")
    long add(@Param("user") Uzer user);

    @Update("update uzer set username = #{user.username},realname = #{user.realname}"//
            + " where id=#{user.id}")
    void update(@Param("user") Uzer user);

    @Delete("delete from uzer where id = #{user.id}")
    void delete(@Param("user") Uzer user);

}
